home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9206.ARJ / 1006048A < prev    next >
Text File  |  1992-06-02  |  5KB  |  205 lines

  1. LISTING THREE
  2.  
  3.  
  4. #include    "channel.hpp"
  5.  
  6. int CHANNEL::wait_for_ring()
  7. {
  8.     printf("Waiting For Ring On: %d\n", lineno);
  9.     clrdtmf(lineno);
  10.     return 0;
  11. }
  12.  
  13.  
  14. void CHANNEL::wait_complete(int evtcode)
  15. {
  16.     // if a call detected, set state to go off hook
  17.     if (evtcode == T_RING)  {
  18.         printf("Ring Detected on: %d\n", lineno);
  19.         begin_func = CHANNEL::offhook;
  20.         end_func   = CHANNEL::offhook_cmplt;
  21.     }
  22. }
  23.  
  24. int CHANNEL::offhook()
  25. {
  26.     // call Dialogic library function to go off hook
  27.     return(sethook(lineno, H_OFFH));
  28. }
  29.  
  30. void CHANNEL::offhook_cmplt(int evtcode)
  31. {
  32.     // if event was the termination of going 
  33.     // off-hook, go to "hello" state
  34.     if (evtcode == T_OFFH)  {  
  35.            begin_func = CHANNEL::hello;
  36.            end_func   = CHANNEL::hello_cmplt;
  37.     }
  38.     else {                // otherwise go back on hook
  39.        begin_func = CHANNEL::onhook;
  40.        end_func   = CHANNEL::onhook_cmplt;
  41.     }
  42. }
  43.  
  44.  
  45. // set phone back on hook
  46. int CHANNEL::onhook()
  47. {
  48.     // call Dialogic library function to go off hook
  49.     return (sethook(lineno, H_ONH));    
  50. }
  51.  
  52. void CHANNEL::onhook_cmplt(int evtcode)
  53. {
  54.     // go back to waiting for a ring
  55.        begin_func = CHANNEL::wait_for_ring; 
  56.     end_func   = CHANNEL::wait_complete;
  57. }
  58.  
  59. int CHANNEL::hello()
  60. {
  61.     strcpy(msgname, "hello");    // play "hello"    msg
  62.     return play();
  63. }
  64.  
  65. void CHANNEL::hello_cmplt(int evtcode)
  66. {
  67.     close(rwb.filehndl);
  68.     // if message reached EOF, get digits from caller
  69.     if (evtcode == T_EOF) {     
  70.            begin_func = CHANNEL::get_digits;
  71.         end_func   = CHANNEL::get_digits_cmplt;
  72.     }
  73.     else {                 // on error, reset phone line
  74.            begin_func = CHANNEL::onhook;
  75.         end_func   = CHANNEL::onhook_cmplt;
  76.     }
  77. }
  78.  
  79. int CHANNEL::get_digits()
  80. {
  81.     printf("Getting Digits On: %d\n", lineno);
  82.     clrrwb(&rwb);      // clear the read-write block
  83.  
  84.     // store segment & offset of buffer in the rwb
  85.     rwb.xferoff  = FP_OFF(digits);
  86.     rwb.xferseg  = FP_SEG(digits);
  87.     rwb.maxdtmf  = 2;       // request 2 keypad digits
  88.     rwb.maxsec   = 10;    // wait 10 seconds      
  89.     rwb.loopsig  = 1;     // terminate on loop signal
  90.  
  91.     // call Dialogic library function to get digits
  92.     return (getdtmfs(lineno, &rwb));
  93. }
  94.  
  95. void CHANNEL::get_digits_cmplt(int evtcode)
  96. {
  97.     // check for maximum dtmf or timeout event
  98.     if (evtcode == T_MAXDT || evtcode == T_TIME) {
  99.         if(!strcmp((char *)digits, "11")) {
  100.                begin_func = CHANNEL::product_info;
  101.             end_func   = CHANNEL::product_info_cmplt;
  102.             return;
  103.         }
  104.         else if(!strcmp((char *)digits, "22")) {
  105.                begin_func = CHANNEL::playback;
  106.             end_func   = CHANNEL::playback_cmplt;
  107.             return;
  108.         }
  109.         else if(!strcmp((char *)digits, "33")) {
  110.                begin_func = CHANNEL::rec_msg;
  111.             end_func   = CHANNEL::rec_msg_cmplt;
  112.             return;
  113.         }
  114.     }
  115.        begin_func = CHANNEL::invalid;
  116.     end_func   = CHANNEL::invalid_cmplt;
  117. }
  118.  
  119. int CHANNEL::product_info()
  120. {
  121.     strcpy(msgname, "PRODUCTS");
  122.     return play();
  123. }
  124.  
  125. void CHANNEL::product_info_cmplt(int evtcode)
  126. {
  127.     close(rwb.filehndl);
  128.        begin_func = CHANNEL::goodbye;
  129.     end_func   = CHANNEL::goodbye_cmplt;
  130. }
  131.  
  132.  
  133. int CHANNEL::playback()
  134. {
  135.     // play back the message which was recorded
  136.     strcpy(msgname, RECORD_FNAME);
  137.     return play();
  138. }
  139.  
  140.  
  141. void CHANNEL::playback_cmplt(int evtcode)
  142. {
  143.     close(rwb.filehndl);
  144.        begin_func = CHANNEL::goodbye;
  145.     end_func   = CHANNEL::goodbye_cmplt;
  146. }
  147.  
  148.  
  149. int CHANNEL::goodbye()
  150. {
  151.     strcpy(msgname, "goodbye");
  152.     return play();
  153. }
  154.  
  155. void CHANNEL::goodbye_cmplt(int evtcode)
  156. {
  157.     close(rwb.filehndl);
  158.        begin_func = CHANNEL::onhook;
  159.     end_func   = CHANNEL::onhook_cmplt;
  160. }
  161.  
  162. int CHANNEL::invalid()
  163. {
  164.     strcpy(msgname, "invalid");
  165.     return play();
  166. }
  167.  
  168. void CHANNEL::invalid_cmplt(int evtcode)
  169. {
  170.     close(rwb.filehndl);
  171.        begin_func = CHANNEL::onhook;
  172.     end_func   = CHANNEL::onhook_cmplt;
  173. }
  174.  
  175.  
  176. int CHANNEL::rec_msg()
  177. {
  178.     char fname[13];
  179.     sprintf(fname, "%s%s", RECORD_FNAME, SPEECH_EXT);
  180.  
  181.     clrrwb(&rwb);       // clear the read/write block
  182.     rwb.filehndl = open(fname, O_WRONLY | O_BINARY | 
  183.             O_CREAT | O_TRUNC,     S_IWRITE | S_IREAD);
  184.     rwb.maxsec  = 20;  // maximum recording length
  185.     rwb.termdtmf= '@'; // stop on any touch tone
  186.     rwb.maxsil  = 5;   // stop if 5 seconds of silence
  187.     rwb.loopsig = 1;   // stop if loop signal
  188.     rwb.rwbflags= 0x02;// beep before starting record
  189.     rwb.rwbdata1= 3;   // beep for .6 second
  190.  
  191.     // call Dialogic library to start recording
  192.     return (recfile(lineno, &rwb, RM_NORM));
  193. }
  194.  
  195.  
  196. void CHANNEL::rec_msg_cmplt(int evtcode)
  197. {
  198.     // clear any touch tone used to stop recording
  199.     close(rwb.filehndl);
  200.     clrdtmf(lineno);         
  201.     // set to now play goodbye message
  202.        begin_func = CHANNEL::goodbye;            
  203.     end_func   = CHANNEL::goodbye_cmplt;
  204. }
  205.